getCSPGroupReturn <- function(groupcode, Pversion=0, n=10, verbose=FALSE, method="close_t0") {
  groupinfo <- getDBGroup(groupcode)  # retrieve table with stock_id, code, from, to
  patternlist <- getCSPGroupPattern(groupcode, Pversion=Pversion)
  patternlistnames <- names(patternlist)
  returns <- list()
  
  for (i in 1:length(patternlist)) {
    symname <- paste(patternlistnames[i], ".vadb", sep="")
    fromtodates <- getGroupMember(groupinfo, patternlistnames[i])
    subsetstring = paste(fromtodates[1], "/", sep="") # ensure that TS and FILTER have same indexes
    if (verbose==TRUE) { print (paste("calculate return of", symname)) }
    CSPatterns <- colnames(patternlist[[i]])
    for (j in 1:length(CSPatterns)) {
      if (verbose==TRUE) { print (paste("..calculate pattern", CSPatterns[j])) }
      TS <- get(symname)[subsetstring]
      rets <- calculateNPeriodReturns(TS, patternlist[[patternlistnames[i]]][,CSPatterns[j]], n=n, 
                                      includeSymName=TRUE, verbose=verbose, method=method)
      #if (dim(rets)[2] == n) {  # rbind only if pattern have been found
      if (length(rets) > 0) {
        returns[[CSPatterns[j]]] <- rbind(returns[[CSPatterns[j]]], rets)
      }
    }
  }
  return(returns)
}
